package org.user.controller;

import com.fasterxml.jackson.core.JsonProcessingException;

import org.common.util.RedisCommon;
import org.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import static org.user.util.StaticVariable.Phone_Code;


@RestController
@CrossOrigin
public class UtilsController {
    @Autowired
    private RedisCommon redisCommon;
    @GetMapping("/getCode/{phone}")
    //获取六位的验证码
    public Result getTemporaryCode(@PathVariable("phone") String phone) throws JsonProcessingException {
        Random random = new Random();
        int code = random.nextInt(900000) + 100000; // 生成100000到999999之间的随机数
        redisCommon.setTemporaryCode(Phone_Code+phone,code+"",2, TimeUnit.MINUTES);
        System.out.println(code);
        return Result.success("获取验证码成功",code);
    }
}
